package com.huawei.petSystemdemo;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.Toast;

import com.huawei.petSystemdemo.adapter.ShopAdressAdapter;
import com.huawei.petSystemdemo.bean.Adress;
import com.huawei.petSystemdemo.data.AdressRepository;
import com.huawei.petSystemdemo.ui.Race.CatActivity;
import com.huawei.petSystemdemo.ui.my.MyFragment;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;

public class ShoppingAdressActivity extends AppCompatActivity {
    private RecyclerView shop_list_adress;
    private ImageView back;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_shopping_adress);

        shop_list_adress = findViewById(R.id.shop_list_adress);
        back=findViewById(R.id.imageView5);

        Intent intent = getIntent();
        int order = intent.getIntExtra("order", -1);

        LinearLayoutManager manager = new LinearLayoutManager(this);
        manager.setOrientation(RecyclerView.VERTICAL);
        shop_list_adress.setLayoutManager(manager);

        GlobalViewModel global = GlobalViewModel.getGlobal();

        List<Adress> adressList = new ArrayList<>();
        if(global.user != null) {
            AdressRepository.getAll(global.user.getId(), new Consumer<List<Adress>>() {
                @Override
                public void accept(List<Adress> adresses) {
                    adressList.addAll(adresses);

                    ShopAdressAdapter adapter = new ShopAdressAdapter(adressList,getBaseContext(),order);
                    shop_list_adress.setAdapter(adapter);
                    System.out.println(adressList.get(0).getimg());
                }
            });
        } else {
            Toast.makeText(ShoppingAdressActivity.this, "还未登录", Toast.LENGTH_SHORT).show();
        }

    }

    public void onClick (android.view.View back){
        Intent intent = new Intent(this, Add_shoppiingadress_Activity.class);//界面跳转
        startActivity(intent);//
    }
    public void onClickBack (android.view.View back){
        Intent intent = new Intent(this,MainActivity2.class);//界面跳转
        startActivity(intent);//
    }
}